package Util;

import java.util.Properties;

public class Language {    
    private Properties lang;
    private static Language instance;

    private Language(String langFile) {
        lang = new java.util.Properties();
        try {
            lang.load(this.getClass().getClassLoader().getResourceAsStream(langFile));
        } catch (Exception eta) {
            eta.printStackTrace();
        }
    }

    private String getValue(String key) {
        String r = lang.getProperty(key);
        if(r == null){
            r = "Error: El código "+key+" no existe en el diccionario.";            
        }
        return r;
    }
    
    public static void loadLanguage(String langFile){                    
        instance = new Language(langFile);        
    }

    public static String getProperty(String key) {
        if (instance == null) {
            instance = new Language("Config/lang.es.properties");
        }
        return instance.getValue(key);
    }    
}
